#include "network/network_interface.h"

#include <asio.hpp>
#include <boost/bind.hpp>

using namespace pita;

using asio::ip::tcp;

NetworkInterface::NetworkInterface(QueueCursorInterface& cursor,
								   PlayerInterface& player) :
	cursor_ (&cursor),
	player_ (&player)
{
	cursor_->changeSignal.connect(
		boost::bind(&NetworkInterface::positionChanged, this));

	player_->playSignal.connect(
		boost::bind(&NetworkInterface::playerPlay, this));

	player_->pauseSignal.connect(
		boost::bind(&NetworkInterface::playerPause, this));
}

void NetworkInterface::run()
{
	try {
		asio::io_service io_service;
		
		tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), 10002));
		
		while (true)
		{
			tcp::socket socket(io_service);
			acceptor.accept(socket);

			
		}
	}
	catch (std::exception& e)
	{
		std::cerr << e.what() << std::endl;
	}
	
}

void NetworkInterface::positionChanged()
{
}

void NetworkInterface::playerPlay()
{
}

void NetworkInterface::playerPause()
{
}
